package com.example.lenovo.weiyi.wxapi;

import android.content.Intent;
import android.os.Bundle;

import com.com.ruanmeng.utils.CommonUtil;
import com.example.lenovo.weiyi.BaseActivity;
import com.example.lenovo.weiyi.R;
import com.example.lenovo.weiyi.SureDDActivity;
import com.example.lenovo.weiyi.ZhiFuSucessActivity;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import com.wxpay.Constants;


public class WXPayEntryActivity extends BaseActivity implements IWXAPIEventHandler {

    private static final String TAG = "MicroMsg.SDKSample.WXPayEntryActivity";

    private IWXAPI api;

    private Intent x;

    private Intent intent;
    public static String wx_kcid="";
    public static String wx_price="";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pay_result);

        api = WXAPIFactory.createWXAPI(this, Constants.APP_ID);

        api.handleIntent(getIntent(), this);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        api.handleIntent(intent, this);
    }

    @Override
    public void onReq(BaseReq req) {
    }

    @Override
    public void onResp(BaseResp resp) {
       /* if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(com.ruanmeng.sizhuosifangke.R.string.app_tip);
            builder.setMessage(getString(com.ruanmeng.sizhuosifangke.R.string.pay_result_callback_msg, resp.errStr + ";code=" + String.valueOf(resp.errCode)));
            builder.show();
        } else {
        }*/

        if (resp.errCode == 0) {
            CommonUtil.showToask(WXPayEntryActivity.this, "支付成功！");
            Intent intent = new Intent(WXPayEntryActivity.this, ZhiFuSucessActivity.class);
            startActivity(intent);
//            Toast.makeText(WXPayEntryActivity.this, resp.errCode + "", Toast.LENGTH_SHORT).show();
//            intent = new Intent(WXPayEntryActivity.this, ZhiFuSucessActivity.class);
//            startActivity(intent);
//              Intent intent = new Intent();
//              intent.setAction("com.jialimei.weixinpay");
//              //要发送的内容
//              intent.putExtra("errCode", resp.errCode);
//              //发送 一个无序广播
//              sendBroadcast(intent);
            finish();

        } else {
//            intent = new Intent(WXPayEntryActivity.this, WXPayEntryActivity.class);
//            startActivity(intent);
//            Toast.makeText(WXPayEntryActivity.this, "支付失败。。。", Toast.LENGTH_SHORT).show();

        }
    }
}